package cn._2dland.net
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;

	[Event(name="complete", type="flash.events.Event")]

	public class PartLoader extends EventDispatcher
	{
		protected var _loader:URLLoader;

		protected var _partName:String;
		protected var _smooth:Boolean;
		protected var _infos:Array;

		public function PartLoader() {
			_loader = new URLLoader();
			_loader.addEventListener(Event.COMPLETE, loadCompleteHandler);
			_loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}

		public function load(partXml:XML):void {
			_partName = partXml.@name;
			_smooth = (partXml.@smooth != 0);

			_infos = new Array();
		}

		public function get infos():Array {
			return _infos;
		}

		public function release():void {
			if(_loader != null) {
				_loader.removeEventListener(Event.COMPLETE, loadCompleteHandler);
				_loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
				try{ _loader.close(); }
				catch(err:Error){ trace(err.message); }
				_loader = null;
			}
		}

		protected function loadCompleteHandler(e:Event):void {}
		protected function ioErrorHandler(e:IOErrorEvent):void {}
	}
}